﻿// <copyright file="MapInfoFileTokeniserTest.cs" company="QUT">
//     Copyright (c) Ninety Nine Percent. All rights reserved.
// </copyright>

using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Qut.GenerateKml.Data
{
    /// <summary>
    /// A class for testing MapInfoFileTokeniser and its super class - MapInfoStringTokeniser.
    /// </summary>
    [TestFixture]
    public class MapInfoFileTokeniserTest
    {
        /// <summary>
        /// Test MapInfoFileTokeniser
        /// </summary>
        private MapInfoFileTokeniser mifToken;

        /// <summary>
        /// The file path.
        /// </summary>
        private string path = "QLD_Federal_Electoral_Boundaries.MID";

        /// <summary>
        /// Initializes the all data member in the test.
        /// </summary>
        [SetUp]
        public void Initialize()
        {
            this.mifToken = new MapInfoFileTokeniser(File.OpenText(this.path));
        }

        /// <summary>
        /// test the ReadLine function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void ReadLineTest()
        {
            Assert.IsTrue(this.mifToken.ReadLine());
        }

        /// <summary>
        /// test the GetToken function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void GetTokenTest1()
        {
            this.mifToken.ReadLine();
            Assert.AreEqual(this.mifToken.GetToken(',', false, false), "1");
        }

        /// <summary>
        /// test the GetToken function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void GetTokenTest2()
        {
            this.mifToken.ReadLine();
            Assert.AreEqual(this.mifToken.GetToken(',', false), "1");
        }

        /// <summary>
        /// test the GetToken function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void GetTokenTest3()
        {
            this.mifToken.ReadLine();
            Assert.AreEqual(this.mifToken.GetToken(','), "1");
        }

        /// <summary>
        /// test the GetToken function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void GetTokenTest4()
        {
            this.mifToken.ReadLine();
            string s = "1,\"Blair\",273,87171,92524,87454,87454,14859.51,\"Blair\"";
            Assert.AreEqual(this.mifToken.GetToken(), s);
        }

        /// <summary>
        /// test the PutToken function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void PutTokenTest()
        {
            this.mifToken.ReadLine();
            this.mifToken.PutToken("Tian");
            string s = "Tian";
            Assert.AreEqual(this.mifToken.GetToken(), s);
        }

        /// <summary>
        /// test the GetLine function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void GetLineTest()
        {
            this.mifToken.ReadLine();
            string s = "1,\"Blair\",273,87171,92524,87454,87454,14859.51,\"Blair\"";
            Assert.AreEqual(this.mifToken.GetLine(), s);
        }

        /// <summary>
        /// test the IsEmpty function of MapInfoStringTokeniser class
        /// </summary>
        [Test]
        public void IsEmptyTest()
        {
            this.mifToken.ReadLine();
            Assert.IsFalse(this.mifToken.IsEmpty());
        }

        /// <summary>
        /// test the GetLineNumber function of MapInfoFileTokeniser class
        /// </summary>
        [Test]
        public void GetLineNumberTest()
        {
            this.mifToken.ReadLine();
            Assert.IsTrue(this.mifToken.GetLineNumber() == 1);
        }
    }
}
